﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace Backend.JYD.Factory
{
    public class DALFactory
    {
        #region DAL ConfigurationManager

        private static readonly string DALPath = ConfigurationManager.AppSettings["Backend.Jyd.DALPath"];

        #endregion

        #region Assembly

        private static Assembly m_assembly = null;
        private static Assembly EFAssembly
        {
            get
            {
                if (m_assembly == null)
                {
                    m_assembly = Assembly.Load(DALPath);
                }
                return m_assembly;
            }
        }

        #endregion

        #region 创建对象处理类

        public static T CreateEFDAL<T>(string classPath)
        {
            string className = DALPath + "." + classPath;
            try
            {
                if (EFAssembly != null)
                {
                    var idal = (T)EFAssembly.CreateInstance(className);
                    return idal;
                }
            }
            catch (Exception ex)
            {
                Backend.JYD.Common.LogHelper.Log("Class:" + className, ex);
            }

            return default(T);
        }


        #endregion
    }
}
